
<meta name="viewport" content="width=device-width" />
<img id="pic" onclick="kaiDeng()" src="1.png" />
<button onclick = "kaiDeng()">开灯</button>

<script>
var i = 1;
function kaiDeng(){
  if(i==1){
    pic.src = "2.png";
    i = 0;
  }else{
    pic.src = "1.png";
    i = 1;
  }
}
</script>